package cn.com.bluemoon.daps.system.service.impl;

import cn.com.bluemoon.daps.system.dto.SystemUserDto;
import cn.com.bluemoon.daps.system.entity.DapSystemLogin;
import cn.com.bluemoon.daps.system.service.DapSystemLoginService;
import cn.com.bluemoon.daps.system.service.DapSystemUserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 基于登录后的用户
 *
 * @author Jarod.Kong
 * @date 2021/3/29 15:20
 */
@Slf4j
@Service(DapSystemUserService.DAP_SYSTEM_LOGIN_USER_SERVICE)
public class DapSystemLoginUserServiceImpl implements DapSystemUserService {

    @Resource
    private DapSystemLoginService systemLoginService;

    /**
     * 获取所有用户信息
     *
     * @return
     */
    @Override
    public List<SystemUserDto> allUsers() {
        List<DapSystemLogin> list = systemLoginService.list(systemLoginService.bmLambdaQuery());
        return list.stream().map(SystemUserDto::new).collect(Collectors.toList());
    }

    @Override
    public List<SystemUserDto> listUsersByAccount(List<String> account) {
        List<DapSystemLogin> list = systemLoginService.listUserByAccount(account);
        return list.stream().map(SystemUserDto::new).collect(Collectors.toList());
    }

    @Override
    public List<SystemUserDto> dbaUsers() {
        LambdaQueryWrapper<DapSystemLogin> wrapper = systemLoginService.bmLambdaQuery()
                .eq(DapSystemLogin::getDbaRole, Boolean.TRUE);
        List<DapSystemLogin> list = systemLoginService.list(wrapper);
        return list.stream().map(SystemUserDto::new).collect(Collectors.toList());
    }
}
